package com.smart.sso.server.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.smart.sso.rpc.UserRpcDto;
import com.smart.sso.rpc.UserRpcService;
import com.smart.sso.server.model.User;
import com.smart.sso.server.service.UserService;

@Service("userRpcService")
public class UserRpcServiceImpl implements UserRpcService{
	@Resource
	private UserService userService;


	@Override
	public List<UserRpcDto> findByUserIds(List<Integer> idList) {
		return userService.findByIds(idList);
	}
	
	@Override
	public List<UserRpcDto> findByUserInfo(List<Integer> idList,String[] roleBusiCodes,Map<String,String> params) {
		return userService.findByUserInfo(idList,roleBusiCodes,params);
	}

	@Override
	public List<UserRpcDto> findByUserIdAndRole(List<Integer> idList,String[] roleBusiCodes) {
		return userService.findByUserIdAndRole(idList,roleBusiCodes);
	}

	@Override
	public List<Integer> findByChargeUserId(Integer chargeUserId, Integer exceptUserId, Boolean isEnable) {
		List<User> userList=userService.findByChargeUserId(chargeUserId, exceptUserId, isEnable);
		List<Integer> idList=new ArrayList<>();
		if(CollectionUtils.isEmpty(userList)) {
			return idList;
		}
		for(User user:userList) {
			idList.add(user.getId());
		}
		return idList;
	}

	@Override
	public List<Integer> findByManagedUserId(Integer managedUserId, Integer exceptUserId) {
		List<User> userList=userService.findByManagedUserId(managedUserId, exceptUserId);
		List<Integer> idList=new ArrayList<>();
		if(CollectionUtils.isEmpty(userList)) {
			return idList;
		}
		for(User user:userList) {
			idList.add(user.getId());
		}
		return idList;
	}

}
